package hmh;
import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

public class Main {
    public static void main(String[] args) {
        /**Get files */
//        List<String> xmlFilePaths = listFilename("/Users/hanminghao/Downloads/Transfer/XBRL-Files");
        List<String> xmlFilePaths = listFilename("/Users/hanminghao/Downloads/Transfer/test");
        /**Combine files */
        try {
            Combine.myCombineXML(xmlFilePaths);
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
//        System.out.println(fileDifference());
    }

    private static long fileDifference() {
        String filePath1 = "/Users/hanminghao/Downloads/Transfer/noTail.xml";
//        String filePath1 ="/Users/hanminghao/Downloads/Transfer/combinedFile";
        String filePath2 = "/Users/hanminghao/Downloads/Transfer/XBRL-Files/Moodys-NRSRO-104-2023-10-15.xml";

        long fileSize1 = getFileSize(filePath1);
        long fileSize2 = getFileSize(filePath2);

        long difference = Math.abs(fileSize1 - fileSize2);
        return difference;
    }
    private static long getFileSize(String filePath) {
        File file = new File(filePath); 
        return file.length();
    }
    private static List<String> listFilename(String folderPath) {
        File folder = new File(folderPath);
        List<String> result = new ArrayList<>();
        // 检查文件夹是否存在并且是一个目录
        if (folder.exists() && folder.isDirectory()) {
            // 获取文件夹中的所有文件
            File[] files = folder.listFiles();

            // 遍历文件数组并打印文件名
            for (File file : files) {
                if (file.isFile()) {
                    result.add(folderPath+"/"+ file.getName());
                }
            }
        } else {
            System.out.println("文件夹不存在或不是一个目录！");
        }
        return result;
    }
}

